home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / OS⁄Toolbox / Sound Input Driver Ex. 1.0 / HackRecorder.a next >
Encoding:
Text File  |  1991-04-08  |  28.6 KB  |  847 lines  |  [TEXT/MPS ]

  1. ;====================================================================================
  2. ;
  3. ;    HackRecorder.a
  4. ;    
  5. ;    Copyright © 1990 Apple Computer, Inc.
  6. ;    
  7. ;    Sound Input Driver Example
  8. ;
  9. ;    Revision History
  10. ;
  11. ;        04/01/91    No changes except added this comment line: Submitted as item for developer CD.
  12. ;        12/10/90    Updated to support continous recording selector.
  13. ;        11/19/90    First created.
  14. ;
  15. ;====================================================================================
  16.  
  17.             INCLUDE        'Traps.a'
  18.             INCLUDE        'SysErr.a'
  19.             INCLUDE        'SysEqu.a'
  20.             INCLUDE        'Sound.a'
  21.         
  22.             CASE        OBJ
  23.             MACHINE        MC68000
  24.  
  25. ;_______________________________________________________________________
  26. ;
  27. ; Constants
  28. ;
  29. ;_______________________________________________________________________
  30.  
  31. rate7khz                    EQU        $1CFA2E8B    ; 7418.1818 samples/second
  32. eightBits                    EQU        8            ; we support 8-bit samples only
  33. hardwareChannels            EQU        1            ; we support only one channel.
  34. oneFactor                    EQU        1            ; compression factor for no compression
  35. siContinousOnOff            EQU        'cont'        ; continous recording selector (will be in interfaces soon)
  36.  
  37. ;_______________________________________________________________________
  38. ;
  39. ; Local driver variables (pointed to by DCtlStorage)
  40. ;
  41. ;_______________________________________________________________________
  42.  
  43. DrvrStorage            RECORD                0
  44. RequestParamPtr        DS.L                1        ; pointer to param block passed in by read,control,etc.
  45. SampleSize            DS.W                1        ; current sample size
  46. SampleRate            DS.L                1        ; current sample rate 
  47. NumberOfChannels    DS.W                1        ; current number of channels
  48. CompType            DS.L                1        ; compression type
  49. AppBufferPtr        DS.L                1        ; pointer to application buffer
  50. AppBufferLength        DS.L                1        ; length of application buffer in bytes
  51. userInterrupt        DS.L                1        ; pointer to user interrupt routine
  52. levelMeterFlag        DS.W                1        ; 1 = level metering on; 0 = level metering off
  53. contFlag            DS.W                1        ; 1 = continous recording on; 0 = continous recording off
  54. pauseFlag            DS.W                1        ; 1 = paused, 0 = unpaused
  55. twosFlag            DS.W                1        ; 1 = return 2's complement sampls, 0 = return offset binary samples
  56. currentLevel        DS.W                1        ; current level meter value
  57. drvrStorageSize        EQU                 *        ; size of DrvrStorage
  58.                     ENDR
  59.  
  60. ;_______________________________________________________________________
  61. ;
  62. ;The code starts here!
  63. ;
  64. ;_______________________________________________________________________
  65.  
  66.             SEG        '.HackRecorder'
  67.             PROC    ENTRY
  68.             WITH    DrvrStorage
  69.  
  70. ;The Driver Header: This is the address installed in the driver's Device Control Entry,
  71. ;so that all the standard Macintosh driver header info is in the right place.
  72.  
  73. HackRecorder    DC.W    $4D00                    ; read, control, status, needs lock
  74.                 DC.W    0                        ; no delay
  75.                 DC.W    0                        ; no EMask
  76.                 DC.W    0                        ; no menu
  77.  
  78. ; Entry point offset table
  79.                 DC.W    HackRecorderOpen-HackRecorder        ; open
  80.                 DC.W    HackRecorderRead-HackRecorder        ; prime
  81.                 DC.W    HackRecorderControl-HackRecorder    ; control
  82.                 DC.W    HackRecorderStatus-HackRecorder        ; status
  83.                 DC.W    HackRecorderClose-HackRecorder        ; close
  84.  
  85.                 STRING    PASCAL
  86. HackRecorderName
  87.                 DC.B    '.HackRecorder'            ; name for this driver
  88.                 ALIGN    2
  89.  
  90. JIOOut            MOVE.L    JIODone,A0                ; use IODone vector
  91.                 JMP        (A0)                    ; we don't come back from this one!
  92.  
  93.  
  94. ;_______________________________________________________________________
  95. ;
  96. ; Routine:    HackRecorderOpen
  97. ; Allocate & initialize driver locals.
  98. ;
  99. ; Arguments:    A0 (input)  -- pointer to request parameter block   (not used in this example)
  100. ;                A1 (input)  -- pointer to disk DCE
  101. ;
  102. ;
  103. ; Registers Used:
  104. ;                A0    -- holds Ptr to the DrvrStorage Data Record
  105. ;                D0    -- temp and result
  106. ;
  107. ;_______________________________________________________________________
  108.  
  109. HackRecorderOpen    
  110.             
  111.             MOVEM.L    D3-D4/A2, -(SP)            ;save registers
  112.             
  113.             MOVE.L    #drvrStorageSize, D0    ; get memory for SoundIn storage variables
  114.             _NewPtr    ,sys,clear                ; storage is now off A0
  115.             MOVE.L    A0, D0
  116.             BEQ.S    noMemory
  117.             
  118.             MOVE.L    A0, dCtlStorage(A1)        ; keep the locals ptr in the DCE
  119.             MOVE.L    A0, A2                    ; we thrash A0 soon
  120.             
  121.             ; Initialize local variables
  122.             
  123.             MOVE.W    #hardwareChannels, NumberOfChannels(A2)     ; 1 channel 
  124.             MOVE.L    #rate22khz, SampleRate(A2)                    ; 22khz
  125.             MOVE.W    #eightBits,SampleSize(A2)                    ; 8 bit samples
  126.             MOVE.L    #noneCompType,CompType(A2)                    ;no compression
  127.             ;MOVE.W    #0,levelMeterFlag(A2)                        ; already cleared above
  128.             MOVE.W    #127,currentLevel(A2)                        ; default level
  129.             
  130.             MOVEQ    #0,D0                    ;success
  131.             MOVEM.L    (SP)+,D3-D4/A2            ;restore  registers
  132.             RTS                                ;All done with Open!
  133.  
  134. noMemory
  135.             MOVE.W    #memFullErr,D0            ;a NewPtr or NewHandle failed
  136.             MOVEM.L    (SP)+,D3-D4/A2            ;restore  registers
  137.             RTS
  138.             
  139.             
  140. ;_______________________________________________________________________
  141. ;
  142. ; Routine:    HackRecorderRead
  143. ; Arguments:    A0 (input)  -- pointer to request parameter block    
  144. ;                A1 (input)  -- pointer to disk DCE
  145. ;
  146. ; The "prime" entry point is used for read only.
  147. ;
  148. ; Registers Used:
  149. ;                A2    -- holds Ptr to the dCtlStorage
  150. ;                A3    -- Ptr to application buffer
  151. ;                D0    -- counter and result
  152. ;                D1    -- generated sample value
  153. ;
  154. ;_______________________________________________________________________
  155.  
  156. HackRecorderRead
  157.             
  158.             MOVEM.L    D3-D7/A3-A5, -(SP)                    ;save all of the registers
  159.             MOVE.L    dCtlStorage(A1), A2                    ;get a pointer to our data record
  160.  
  161.             MOVE.L    A0, RequestParamPtr(A2)                ;save pointer to the request parameter block
  162.             MOVE.L    ioBuffer(A0), AppBufferPtr(A2)        ;save pointer to the application buffer
  163.             MOVE.L    ioReqCount(A0), AppBufferLength(A2)    ;save # of bytes to read
  164.  
  165. ;            Here is where you would start your hardware recording. This example
  166. ;            just generates a square wave and returns.
  167.  
  168.             MOVEQ    #0,D1
  169.             MOVE.L    ioBuffer(A0),A3                        ;start at top of applicaton buffer
  170.             MOVE.L    ioReqCount(A0),D0                    ;generate this many samples
  171.             BRA.S    @loopCheck                            ;go to loop check to decrement counter first time through
  172.  
  173. @loopStart
  174.             MOVE.B    D1,(A3)+                            ;store sample in application buffer
  175.             MOVE.L    D0,D2
  176.             ANDI.W    #$0007,D2                            ;time to switch square wave phase?
  177.             BNE.S    @loopCheck                            ;no, so continue
  178.             NOT.B    D1                                    ;toggle square wave phase
  179.             
  180. @loopCheck    SUBQ.L    #1,D0
  181.             BNE.S    @loopStart
  182.  
  183.             MOVE.L    ioReqCount(A0),ioActCount(A0)        ;store the # bytes recorded
  184.             
  185.             MOVEM.L    (SP)+,D3-D7/A3-A5                    ;restore all of the registers
  186.  
  187.             BRA        JIOOut                                ;common exit to JIODone
  188.  
  189.  
  190. ;_______________________________________________________________________
  191. ;
  192. ; Routine:        HackRecorderControl
  193. ; Arguments:    A0 (input)  -- pointer to control call parameter block
  194. ;                A1 (input)  -- pointer to this device's DCE
  195. ;
  196. ;
  197. ;_______________________________________________________________________
  198.  
  199. HackRecorderControl    
  200.             
  201.             MOVEM.L    A2-A3,-(SP)                    ;save unpreserved regs; restored in CSJIOOut & CSJIOErrorOut
  202.  
  203.             MOVE.L    DCtlStorage(A1),A2            ;get ptr to our storage
  204.             MOVE.W    CSCode(A0),D0                ;get the control code
  205.             BEQ.S    ctCodeBad
  206.             SUBQ.W    #1,D0                        ;is csCode = KillIO
  207.             BEQ        killIO
  208.             SUBQ.W    #1,D0                        ;is csCode = 2 then this is our InfoType code
  209.             BEQ.S    ctcodeOK
  210. ctCodeBad
  211.             MOVE    #controlErr,D0
  212.             BRA        CSJIOErrorOut                ;common exit to JIODone
  213.             
  214. ctcodeOK    MOVE.L    csParam(A0),D0                ;csParam contains the data passed to the control call
  215.             
  216.             CMPI.L    #siInitializeDriver,D0
  217.             BEQ.S    InitDriverState
  218.             
  219.             CMPI.L    #siCloseDriver,D0
  220.             BEQ.S    CloseDriverState
  221.             
  222.             CMPI.L    #siPauseRecording,D0
  223.             BEQ        setPause
  224.  
  225.             CMPI.L    #siRecordingQuality,D0
  226.             BEQ        setQuality
  227.             
  228.             CMPI.L    #siSampleSize,D0
  229.             BEQ        setSampleSize
  230.             
  231.             CMPI.L    #siSampleRate,D0
  232.             BEQ        setSampleRate
  233.             
  234.             CMPI.L    #siNumberChannels,D0
  235.             BEQ        setNumberOfChannels
  236.             
  237.             CMPI.L    #siCompressionType,D0
  238.             BEQ        setCompression
  239.             
  240.             CMPI.L    #siLevelMeterOnOff,D0
  241.             BEQ        setLevelMeter
  242.             
  243.             CMPI.L    #siContinousOnOff,D0
  244.             BEQ        setContinuous
  245.             
  246.             CMPI.L    #siTwosComplementOnOff,D0
  247.             BEQ        setTwos
  248.             
  249.             CMPI.L    #siUserInterruptProc,D0
  250.             BEQ        setUserInterrupt
  251.  
  252.             MOVE    #siUnknownInfoType,D0
  253.             BRA        CSJIOErrorOut                ;common exit to JIODone
  254.  
  255. ;----------------------------------------------------------------------------------------------
  256.  
  257. killIO
  258.  
  259. ;            Here you want to stop recording with your hardware. If an asynchronous
  260. ;            Read was in progress, you would disable your hardware interrupt here. This
  261. ;            example is always synchronous, so it just returns.
  262.  
  263.             MOVEM.L    (SP)+,A2-A3                        ;save unpreserved regs
  264.             RTS                                        ;KillIO call MUST return by an RTS
  265.             
  266. ;----------------------------------------------------------------------------------------------
  267.  
  268. InitDriverState 
  269. CloseDriverState 
  270.  
  271. ;            Init: Here you want to allocate your hardware and initialize default settings.
  272. ;            Close: Deallocate your hardware and reset settings.
  273. ;            This example just initializes globals for both selectors.
  274.  
  275.             MOVE.W    #hardwareChannels,NumberOfChannels(A2)     ; 1 channel 
  276.             MOVE.L    #rate22khz,SampleRate(A2)                ; 22khz
  277.             MOVE.W    #eightBits,SampleSize(A2)                ; 8-bit samples
  278.             MOVE.L    #noneCompType,CompType(A2)                ; no compression
  279.             MOVE.W    #0,levelMeterFlag(A2)                    ; no level metering
  280.             
  281.             BRA        CSJIOOut                                ; common exit to JIODone
  282.  
  283. ;----------------------------------------------------------------------------------------------
  284.  
  285. setPause
  286.  
  287. ;            Here you want to pause your hardware. This can be done by setting a pause flag
  288. ;            which tells the interrupt service routine to not copy samples to the application
  289. ;            buffer until the flag is cleared again. This example just stores the pause setting.
  290.  
  291.             MOVE.W    csParam+4(A0),pauseFlag(A2)        ;store new pause setting
  292.  
  293.             BRA        CSJIOOut                        ;common exit to JIODone
  294.  
  295. ;----------------------------------------------------------------------------------------------
  296.  
  297. setQuality
  298.  
  299. ;            Here you want to set up various recording features depending on the quality passed.
  300. ;            This example just changes the rate depending on the quality.
  301.  
  302.             MOVE.L    csParam+4(A0),D0                ;get the quality type
  303.             
  304.             CMPI.L    #siBestQuality,D0                ;best quality?
  305.             BNE.S    @tryBetter
  306.             MOVE.L    #rate22khz,SampleRate(A2)        ;use 22 kHz
  307.             BRA.S    @qualityOK
  308.  
  309. @tryBetter    CMPI.L    #siBetterQuality,D0                ;better quality?
  310.             BNE.S    @tryGood
  311.             MOVE.L    #rate11khz,SampleRate(A2)        ;use 11 kHz
  312.             BRA.S    @qualityOK
  313.  
  314. @tryGood    CMPI.L    #siGoodQuality,D0                ;good quality?
  315.             BNE.S    @unknown
  316.             MOVE.L    #rate7khz,SampleRate(A2)        ;use 7 kHz
  317.  
  318. @qualityOK    MOVE.W    #hardwareChannels,NumberOfChannels(A2)        ; 1 channel
  319.             MOVE.W    #eightBits,SampleSize(A2)        ;8-bit samples
  320.             MOVE.L    #noneCompType,CompType(A2)        ;no compression
  321.             BRA        CSJIOOut                        ;common exit to JIODone
  322.             
  323. @unknown    MOVE    #siUnknownQuality,D0            ;quality not supported
  324.             BRA        CSJIOErrorOut                    ;common exit to JIODone with error
  325.  
  326. ;----------------------------------------------------------------------------------------------
  327.  
  328. setSampleSize
  329.             MOVE.W    csParam+4(A0),D0                ;get the sample size
  330.             
  331.             CMPI.W    #eightBits,D0                    ;we only support 8-bit samples
  332.             BNE.S    @unknown
  333.             BRA        CSJIOOut                        ;common exit to JIODone
  334.  
  335. @unknown    MOVE    #siInvalidSampleSize,D0            ;sample size not supported
  336.             BRA        CSJIOErrorOut                    ;common exit to JIODone with error
  337.  
  338. ;----------------------------------------------------------------------------------------------
  339.  
  340. setSampleRate
  341.             MOVE.L    csParam+4(A0),D0                ;get the compression type
  342.             
  343.             CMPI.L    #rate22khz,D0                    ;is is 22 kHz?
  344.             BEQ.S    @rateOk
  345.  
  346.             CMPI.L    #rate11khz,D0                    ;is is 11 kHz?
  347.             BEQ.S    @rateOk
  348.  
  349.             CMPI.L    #rate7khz,D0                    ;is is 7 kHz?
  350.             BEQ.S    @rateOk
  351.  
  352.             MOVE    #siInvalidSampleRate,D0            ;sample rate not supported
  353.             BRA        CSJIOErrorOut                    ;common exit to JIODone with error
  354.  
  355. @rateOK        MOVE.L    D0,SampleRate(A2)                ;save new rate
  356.             BRA        CSJIOOut                        ;common exit to JIODone
  357.  
  358. ;----------------------------------------------------------------------------------------------
  359.  
  360. setNumberOfChannels
  361.             MOVE.W    csParam+4(A0),D0                ;get the number of channels
  362.             
  363.             CMPI.W    #hardwareChannels,D0            ;we only support 1 channel
  364.             BNE.S    @unknown
  365.             BRA        CSJIOOut                        ;common exit to JIODone
  366.  
  367. @unknown    MOVE    #notEnoughHardware,D0            ;hardware does not support this many channels
  368.             BRA        CSJIOErrorOut                    ;common exit to JIODone with error
  369.  
  370. ;----------------------------------------------------------------------------------------------
  371.  
  372. setCompression
  373.             MOVE.L    csParam+4(A0),D0                ;get the compression type
  374.             
  375.             CMPI.L    #noneCompType,D0                ;we only support no compression
  376.             BNE.S    @unknown
  377.             BRA        CSJIOOut                        ;common exit to JIODone
  378.  
  379. @unknown    MOVE    #siInvalidCompression,D0        ;compression type not supported
  380.             BRA        CSJIOErrorOut                    ;common exit to JIODone with error
  381.  
  382. ;----------------------------------------------------------------------------------------------
  383.  
  384. setLevelMeter
  385.  
  386. ;            Here you may want to start recording into an internal buffer and calculating a
  387. ;            meter level value during the interrupt.
  388.  
  389.             MOVE.W    csParam+4(A0),levelMeterFlag(A2)    ;store new level meter setting
  390.             
  391.             BRA        CSJIOOut                        ;common exit to JIODone
  392.  
  393. ;----------------------------------------------------------------------------------------------
  394.  
  395. setContinuous
  396.  
  397. ;            This flag tells the Read routine to record data to an internal ring buffer
  398. ;            between Read calls. This example is synchronous, so it does not need to do this.
  399.  
  400.             MOVE.W    csParam+4(A0),contFlag(A2)        ;store new continous setting
  401.  
  402.             BRA        CSJIOOut                        ;common exit to JIODone
  403.  
  404. ;----------------------------------------------------------------------------------------------
  405.  
  406. setTwos
  407.  
  408. ;            If this flag is set, you need to convert the samples to two's complement before
  409. ;            writing them to the application buffer. This can be done easily by XOR-ing each
  410. ;            sample with $80 (ie. EORI.B  #$80,D0). This example does not do this, but your
  411. ;            driver should.
  412.  
  413.             MOVE.W    csParam+4(A0),twosFlag(A2)        ;store new two's complement setting
  414.  
  415.             BRA        CSJIOOut                        ;common exit to JIODone
  416.  
  417. ;----------------------------------------------------------------------------------------------
  418.  
  419. setUserInterrupt
  420.  
  421. ;            Store the proc pointer to call every interrupt. This example is synchronous,
  422. ;            so it does not call this routine.
  423.  
  424.             MOVE.L    csParam+4(A0),userInterrupt(A2)        ;store user interrupt proc
  425.             
  426.             BRA        CSJIOOut                        ;common exit to JIODone
  427.  
  428.  
  429. ;_______________________________________________________________________
  430. ;
  431. ; Routine:    HackRecorderStatus
  432. ; Arguments:    A0 (input)  -- pointer to control call parameter block
  433. ;                A1 (input)  -- pointer to this device's DCE
  434. ;
  435. ;_______________________________________________________________________
  436.  
  437. HackRecorderStatus    
  438.  
  439.             MOVEM.L    A2-A3,-(SP)                    ;save unpreserved regs
  440.             
  441.             MOVE.L    DCtlStorage(A1),A2            ;get ptr to our storage
  442.             MOVE.W    CSCode(A0),D0                ;get the control code
  443.             BEQ.S    stCodeBad
  444.             SUBQ.W    #2,D0                        ;is csCode = 2 then this is our InfoType code
  445.             BEQ.S    stcodeOK
  446. stCodeBad
  447.             MOVE    #statusErr,D0
  448.             BRA        CSJIOErrorOut                ;common exit to JIODone
  449.  
  450.  
  451. stcodeOK    MOVE.L    csParam(A0),D0                ;csParam contains the data passed to the control call
  452.             
  453.             CMPI.L    #siPauseRecording,D0
  454.             BEQ        getPause
  455.  
  456.             CMPI.L    #siSampleSize,D0
  457.             BEQ        getCurrentSampleSize
  458.             
  459.             CMPI.L    #siSampleSizeAvailable,D0
  460.             BEQ        getSampleSizes
  461.  
  462.             CMPI.L    #siSampleRate,D0
  463.             BEQ        getCurrentSampleRate
  464.             
  465.             CMPI.L    #siSampleRateAvailable,D0
  466.             BEQ        getSampleRates
  467.             
  468.             CMPI.L    #siNumberChannels,D0
  469.             BEQ        getNumberOfChannels
  470.             
  471.             CMPI.L    #siChannelAvailable,D0
  472.             BEQ        getNumberOfChannelsAvailable
  473.                         
  474.             CMPI.L    #siCompressionType,D0
  475.             BEQ        getCompression
  476.             
  477.             CMPI.L    #siCompressionAvailable,D0
  478.             BEQ        getCompressionTypes
  479.             
  480.             CMP.L    #siCompressionFactor,D0
  481.             BEQ        getCompressionFactor
  482.  
  483.             CMPI.L    #siLevelMeterOnOff,D0
  484.             BEQ        getLevelMeterOnOff            
  485.             
  486.             CMPI.L    #siContinousOnOff,D0
  487.             BEQ        getContinuous
  488.             
  489.             CMPI.L    #siAsync,D0
  490.             BEQ        getAsync
  491.             
  492.             CMPI.L    #siDeviceConnected,D0
  493.             BEQ        deviceConnected
  494.             
  495.             CMPI.L    #siTwosComplementOnOff,D0
  496.             BEQ        getTwos
  497.             
  498.             CMPI.L    #siDeviceBufferInfo,D0
  499.             BEQ        getBufferSize
  500.  
  501.             CMPI.L    #siDeviceName,D0
  502.             BEQ        getDeviceName
  503.             
  504.             CMPI.L    #siDeviceIcon,D0
  505.             BEQ        getDeviceIcon
  506.  
  507.             MOVE    #siUnknownInfoType,D0
  508.             BRA        CSJIOErrorOut                        ; common exit to JIODone
  509.  
  510. ;----------------------------------------------------------------------------------------------
  511.  
  512. getPause
  513.             MOVE.L    #2,csParam(A0)                        ; number of bytes of data sent back
  514.             MOVE.W    pauseFlag(A2),csParam+4(A0)            ; return current pause state
  515.  
  516.             BRA        CSJIOOut                            ; common exit to JIODone
  517.  
  518. ;----------------------------------------------------------------------------------------------
  519.  
  520. getCurrentSampleSize
  521.             MOVE.L    #2,csParam(A0)                        ; number of bytes of data sent back
  522.             MOVE.W    SampleSize(A2),csParam+4(A0)        ; return current sample size in use by our hardware
  523.  
  524.             BRA        CSJIOOut                            ; common exit to JIODone
  525.  
  526. ;----------------------------------------------------------------------------------------------
  527.  
  528. getSampleSizes
  529.             MOVE.L    #6,csParam(A0)                        ; number of bytes of data sent back
  530.             
  531.             MOVE.L    A0,A3                                ; NewHandle trashes A0 so use A3
  532.             MOVE.L    #2,D0                                ; make room for one sample size
  533.             _NewHandle
  534.             BEQ.S    @handleOK                            ; trap dispatcher tests D0
  535.             
  536.             MOVE.L    A3,A0                                ; get drvr param block ptr back into A0
  537.             BRA        CSJIOErrorOut                        ; common exit to JIODone with error
  538.             
  539. @handleOK
  540.             MOVE.L    (A0),A2                                ; get Ptr to data block
  541.             MOVE.W    #eightBits,(A2)                        ; eight bits per sample is our only option
  542.             MOVE.W    #1,csParam+4(A3)                    ; number of sample sizes we support
  543.             MOVE.L    A0,csParam+6(A3)                    ; return handle to table
  544.  
  545.             MOVE.L    A3,A0                                ; get drvr param block ptr back into A0
  546.  
  547.             BRA        CSJIOOut                            ; common exit to JIODone
  548.                                                 
  549. ;----------------------------------------------------------------------------------------------
  550.  
  551. getCurrentSampleRate 
  552.             MOVE.L    #4,csParam(A0)                        ; number of bytes of data sent back
  553.             MOVE.L    SampleRate(A2),csParam+4(A0)        ; return current sample rate in use by our hardware
  554.  
  555.             BRA        CSJIOOut                            ; common exit to JIODone
  556.             
  557. ;----------------------------------------------------------------------------------------------
  558.  
  559. getSampleRates
  560.             MOVE.L    #6,csParam(A0)                        ; number of bytes of data sent back
  561.             
  562.             MOVE.L    A0,A3                                ; NewHandle trashes A0 so use A3
  563.             MOVE.L    #12,D0                                ; make room for three sample rates
  564.             _NewHandle
  565.             BEQ.S    @handleOK                            ; trap dispatcher tests D0
  566.             
  567.             MOVE.L    A3,A0                                ; get drvr param block ptr back into A0
  568.             BRA        CSJIOErrorOut                        ; common exit to JIODone with error
  569.             
  570. @handleOK
  571.             MOVE.L    (A0),A2                                ; get Ptr to data block
  572.             MOVE.L    #rate22khz,(A2)                        ; stuff rates we support into handle
  573.             MOVE.L    #rate11khz,4(A2)
  574.             MOVE.L    #rate7khz,8(A2)
  575.             MOVE.W    #3,csParam+4(A3)                    ; we support 3 sample rates
  576.             MOVE.L    A0,csParam+6(A3)                    ; return handle to table
  577.  
  578.             MOVE.L    A3,A0                                ; get drvr param block ptr back into A0
  579.  
  580.             BRA        CSJIOOut                            ; common exit to JIODone
  581.  
  582. ;----------------------------------------------------------------------------------------------
  583.  
  584. getNumberOfChannels
  585.             MOVE.L    #2,csParam(A0)                        ; number of bytes of data sent back
  586.             MOVE.W    NumberOfChannels(A2),csParam+4(A0)    ; return the number of channels in use by our hardware
  587.  
  588.             BRA        CSJIOOut                            ; common exit to JIODone
  589.  
  590. ;----------------------------------------------------------------------------------------------
  591.  
  592. getNumberOfChannelsAvailable
  593.             MOVE.L    #2,csParam(A0)                        ; number of bytes of data sent back
  594.             MOVE.W    #hardwareChannels,csParam+4(A0)        ; only one channel avail here
  595.  
  596.             BRA        CSJIOOut                            ; common exit to JIODone
  597.             
  598. ;----------------------------------------------------------------------------------------------
  599.  
  600. getCompression
  601.             MOVE.L    #4,csParam(A0)                        ; number of bytes of data sent back
  602.             MOVE.L    #noneCompType,csParam+4(A0)            ; return the compression OSType
  603.  
  604.             BRA        CSJIOOut                            ; common exit to JIODone
  605.  
  606. ;----------------------------------------------------------------------------------------------
  607.  
  608. getCompressionTypes
  609.  
  610. ;            Even though this example does not support compression, you still want to create a
  611. ;            handle of zero length and return it to the applicaton, setting the number of
  612. ;            compression types to zero. This way the application always has a handle to dispose
  613. ;            after making this call.
  614.  
  615.             MOVE.L    #6,csParam(A0)                        ; number of bytes of data sent back
  616.             
  617.             MOVE.L    A0,A3                                ; NewHandle trashes A0 so use A3
  618.             MOVE.L    #0,D0                                ; we don't support any compression, so return 0-length handle
  619.             _NewHandle
  620.             BEQ.S    @handleOK                            ; trap dispatcher tests D0
  621.             
  622.             MOVE.L    A3,A0                                ; get drvr param block ptr back into A0
  623.             BRA        CSJIOErrorOut                        ; common exit to JIODone with error
  624.             
  625. @handleOK
  626.             MOVE.W    #0,csParam+4(A3)                    ; we don't support any compression types
  627.             MOVE.L    A0,csParam+6(A3)                    ; return handle to table
  628.  
  629.             MOVE.L    A3,A0                                ; get drvr param block ptr back into A0
  630.  
  631.             BRA        CSJIOOut                            ; common exit to JIODone
  632.  
  633. ;----------------------------------------------------------------------------------------------
  634.  
  635. getCompressionFactor
  636.             MOVE.L    #2,csParam(A0)                        ; number of bytes of data sent back
  637.             MOVE.W    #oneFactor,csParam+4(A0)            ; return compression factor
  638.  
  639.             BRA        CSJIOOut                            ; common exit to JIODone
  640.  
  641. ;----------------------------------------------------------------------------------------------
  642.  
  643. getLevelMeterOnOff
  644.             MOVE.L    #4,csParam(A0)                        ; number of bytes of data sent back
  645.             MOVE.W    levelMeterFlag(A2),csParam+4(A0)    ; return the level meter On/Off Flag
  646.             MOVE.W    currentLevel(A2),csParam+6(A0)        ; return the current meter level
  647.  
  648.             BRA        CSJIOOut                            ; common exit to JIODone
  649.  
  650. ;----------------------------------------------------------------------------------------------
  651.  
  652. getContinuous
  653.             MOVE.L    #2,csParam(A0)                        ; number of bytes of data sent back
  654.             MOVE.W    contFlag(A2),csParam+4(A0)            ; return current continous recording setting
  655.  
  656.             BRA        CSJIOOut                            ; common exit to JIODone
  657.  
  658. ;----------------------------------------------------------------------------------------------
  659.  
  660. getAsync
  661.             MOVE.L    #2,csParam(A0)                        ; number of bytes of data sent back
  662.             MOVE.W    #0,csParam+4(A0)                    ; we do not support asynchronous driver calls
  663.  
  664.             BRA        CSJIOOut                            ; common exit to JIODone
  665.             
  666. ;----------------------------------------------------------------------------------------------
  667.  
  668. deviceConnected
  669.             MOVE.L    #2,csParam(A0)                        ; number of bytes of data sent back
  670.             MOVE.W    #siDeviceIsConnected,csParam+4(A0)    ; device is plugged in and ready to go
  671.             BRA        CSJIOOut                            ; common exit to JIODone
  672.  
  673. ;----------------------------------------------------------------------------------------------
  674.  
  675. getTwos
  676.             MOVE.L    #2,csParam(A0)                        ; number of bytes of data sent back
  677.             MOVE.W    twosFlag(A2),csParam+4(A0)            ; return current two's complement setting
  678.  
  679.             BRA        CSJIOOut                            ; common exit to JIODone
  680.  
  681. ;----------------------------------------------------------------------------------------------
  682.  
  683. getBufferSize
  684.             MOVE.L    #4,csParam(A0)                        ; number of bytes of data sent back
  685.             MOVE.L    #0,csParam+4(A0)                    ; return size of internal buffer
  686.  
  687.             BRA        CSJIOOut                            ; common exit to JIODone
  688.  
  689. ;----------------------------------------------------------------------------------------------
  690.  
  691. getDeviceName
  692.             MOVE.L    #0,csParam(A0)                        ; number of bytes of data sent back
  693.             MOVE.L    csParam+4(A0),A1                    ; Ptr to name space
  694.             MOVE.L    A0,-(SP)                            ; save the param Ptr
  695.             LEA        @deviceName,A0                        ; Ptr to this device's name
  696.             MOVEQ    #0,D0
  697.             MOVE.B    (A0),D0                                ; length of the name string
  698.             ADDQ    #1,D0                                ; don't forget the length byte
  699.             _BlockMove
  700.  
  701.             MOVE.L    (SP)+,A0                            ; restore the param Ptr
  702.             BRA        CSJIOOut                            ; common exit to JIODone
  703.  
  704.             STRING    PASCAL
  705. @deviceName    DC.B    'HackRecorder'                
  706.             ALIGN    2
  707.  
  708. ;----------------------------------------------------------------------------------------------
  709.  
  710. getDeviceIcon
  711.             MOVE.L    #4,csParam(A0)                        ; number of bytes of data sent back
  712.             
  713.             MOVE.L    A0,A3                                ; NewHandle trashes A0 so use A3
  714.             MOVE.L    #256,D0                                ; make room for icon data
  715.             _NewHandle
  716.             BEQ.S    @handleOK                            ; trap dispatcher tests D0
  717.             
  718.             MOVE.L    A3,A0                                ; get drvr param block ptr back into A0
  719.             BRA        CSJIOErrorOut
  720.             
  721. @handleOK
  722.             MOVE.L    A0,csParam+4(A3)                    ; return handle to icon
  723.             MOVE.L    (A0),A1                                ; get Ptr to data block
  724.             LEA        @deviceIcon,A0                        ; Ptr to this device's name
  725.             MOVE.L    #256,D0                                ; length of the Icon data
  726.             _BlockMove                                    ; copy icon and mask to handle
  727.  
  728.             MOVE.L    A3,A0                                ; get drvr param block ptr back into A0
  729.             BRA        CSJIOOut                            ; common exit to JIODone
  730.  
  731. @deviceIcon    
  732. ; Device Icon
  733.             DC.W    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0600
  734.             DC.W    $0000,$0900,$0000,$1200,$0000,$2100,$0000,$4080
  735.             DC.W    $0000,$4240,$0000,$8230,$0000,$8018,$0001,$0018
  736.             DC.W    $0002,$00F0,$0006,$06C0,$000E,$0946,$001C,$08C0
  737.             DC.W    $003C,$7008,$0078,$7024,$30F0,$7020,$4908,$3000
  738.             DC.W    $9208,$1000,$A209,$1000,$A409,$1000,$A449,$1000
  739.             DC.W    $A849,$1000,$9049,$1000,$8045,$8800,$4082,$4400
  740.             DC.W    $3FFC,$3800,$0000,$0000,$0000,$0000,$0000,$0000
  741.  
  742.             DC.W    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0600
  743.             DC.W    $0000,$0F00,$0000,$1E00,$0000,$3F00,$0000,$7F80
  744.             DC.W    $0000,$7FC0,$0000,$FFF0,$0000,$FFF8,$0001,$FFF8
  745.             DC.W    $0003,$FFF0,$0007,$FFC0,$000F,$F9C6,$001F,$F8C0
  746.             DC.W    $003F,$F008,$007F,$F024,$30FF,$F020,$79FF,$F000
  747.             DC.W    $F3FF,$F000,$E3FF,$F000,$E7FF,$F000,$E7FF,$F000
  748.             DC.W    $EFFF,$F000,$FFFF,$F000,$FFFF,$F800,$7FFE,$7C00
  749.             DC.W    $3FFC,$3800,$0000,$0000,$0000,$0000,$0000,$0000
  750.  
  751. ;----------------------------------------------------------------------------------------------
  752.  
  753. ;    Common exit for control and status calls
  754.  
  755. CSJIOOut
  756.             MOVEQ    #0,D0                        ;noError if Select exits here
  757. CSJIOErrorOut
  758.             MOVE.W    ioTrap(A0),D1
  759.             BTST.L    #noQueueBit,D1                ;is this call an immediate call?
  760.             MOVEM.L    (SP)+,A2-A3                    ;save unpreserved regs
  761.             BNE.S    @isImmediate
  762.             
  763.             BRA        JIOOut                        ;common exit to JIODone
  764.  
  765. @isImmediate
  766.             RTS
  767.             
  768. ;_______________________________________________________________________
  769. ;
  770. ; Routine:      HackRecorderClose
  771. ; Arguments:    A0 (input)  -- pointer to call parameter block
  772. ;                A1 (input)  -- pointer to this device's DCE
  773. ;
  774. ;_______________________________________________________________________
  775.  
  776. HackRecorderClose    
  777.             MOVE.L    dCtlStorage(A1),A2            ;keep the locals ptr in the DCE
  778.             
  779.             MOVE.L    A2,A0                        ;dispose driver storage area
  780.             _DisposPtr
  781.  
  782.             RTS                        
  783.             
  784.             END
  785.  
  786.  
  787. ;_______________________________________________________________________
  788. ;_______________________________________________________________________
  789. ;    
  790. ;    struct DCtlEntry 
  791. ;    {
  792. ;        Ptr        dCtlDriver;        /* Pointer to ROM driver or Handle to RAM driver. */    
  793. ;        short    dCtlFlags;        /* Flags. */
  794. ;        QHdr    dCtlQHdr;        /* Driver I/O queue Header. */
  795. ;        long    dCtlPosition;    /* Byte position used by read & write calls. */
  796. ;        Handle    dCtlStorage;    /* Handle to RAM driver's private storage. */
  797. ;        short    dCtlRefNum;        /* Driver reference number. */
  798. ;        long    dCtlCurTicks;    /* Not used here. */
  799. ;        WindowPtr dCtlWindow;    /* Not used here. */
  800. ;        short     dCtlDelay;        /* Not used here. */
  801. ;        short     dCtlEMask;        /* Not used here. */
  802. ;        short     dCtlMenu;        /* Not used here. */
  803. ;    };
  804. ;    
  805. ;#define ParamBlockHeader \
  806. ;    QElemPtr qLink;                 /*queue link in header*/\
  807. ;    short qType;                    /*type byte for safety check*/\
  808. ;    short ioTrap;                   /*FS: the Trap*/\
  809. ;    Ptr ioCmdAddr;                  /*FS: address to dispatch to*/\
  810. ;    ProcPtr ioCompletion;           /*completion routine addr (0 for synch calls)*/\
  811. ;    OSErr ioResult;                 /*result code*/\
  812. ;    StringPtr ioNamePtr;            /*ptr to Vol:FileName string*/\
  813. ;    short ioVRefNum;                /*volume refnum (DrvNum for Eject and MountVol)*/
  814. ;
  815. ;
  816. ;struct IOParam {
  817. ;    ParamBlockHeader 
  818. ;    short ioRefNum;                 /*refNum for I/O operation*/
  819. ;    char ioVersNum;                 /*version number*/
  820. ;    char ioPermssn;                 /*Open: permissions (byte)*/
  821. ;    Ptr ioMisc;                     /*Rename: new name (GetEOF,SetEOF: logical end of file) (Open: optional ptr to buffer) (SetFileType: new type)*/
  822. ;    Ptr ioBuffer;                   /*data buffer Ptr*/
  823. ;    long ioReqCount;                /*requested byte count; also = ioNewDirID*/
  824. ;    long ioActCount;                /*actual byte count completed*/
  825. ;    short ioPosMode;                /*initial file positioning*/
  826. ;    long ioPosOffset;               /*file position offset*/
  827. ;};
  828. ;
  829. ;
  830. ;struct CntrlParam {
  831. ;    QElem *qLink;                   /*queue link in header*/
  832. ;    short qType;                    /*type byte for safety check*/
  833. ;    short ioTrap;                   /*FS: the Trap*/
  834. ;    Ptr ioCmdAddr;                  /*FS: address to dispatch to*/
  835. ;    ProcPtr ioCompletion;           /*completion routine addr (0 for synch calls)*/
  836. ;    OSErr ioResult;                 /*result code*/
  837. ;    StringPtr ioNamePtr;            /*ptr to Vol:FileName string*/
  838. ;    short ioVRefNum;                /*volume refnum (DrvNum for Eject and MountVol)*/
  839. ;    short ioCRefNum;                /*refNum for I/O operation*/
  840. ;    short csCode;                   /*word for control status code*/
  841. ;    short csParam[11];              /*operation-defined parameters*/
  842. ;};
  843. ;
  844. ;_______________________________________________________________________
  845. ;_______________________________________________________________________
  846.